package cb.wzby;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ListDemo7 {
    public static void main(String[] args) {
        List<Integer> l1 = new ArrayList<>(List.of(1,10,2,5,3,30,5,6,8,9,7));
        System.out.println("==Collections.sort()升降序==");
        System.out.println(l1);
        Collections.sort(l1);
        // Collections.sort()升序
        System.out.println(l1);
        Collections.sort(l1,(a,b) -> b-a);
        //Collections.sort(l1,(a,b) -> b-a)降序
        System.out.println(l1);
        Collections.shuffle(l1);
        //Collections.shuffle()洗牌乱序
        System.out.println(l1);
        List<String> l2 = new ArrayList<>(List.of("java","php","css","c++xs","html"));
        System.out.println(l2);
        Collections.sort(l2);
        System.out.println(l2);
        Collections.sort(l2,(a,b) -> b.compareTo(a));
        //compareTo(String str) 按字典顺序比较两个字符串
        System.out.println(l2);
        Collections.shuffle(l2);
        System.out.println(l2);
        Collections.sort(l2,(a,b) ->a.length()-b.length());
        //长度排序
        System.out.println(l2);


    }
}
